/*
 * webview方法封装
 */

window._WEBVIEW = {
	show: function(id, animation, time, showedCB, extras) {
		var view = plus.webview.getWebviewById(id);
		animation = animation || 'slide-in-right';
		time = time || '350';
		extras = extras || {};
		if(view) {
			var children = view.children();
			view.show(animation, time, showedCB, extras);
			mui.fire(view,'show');
			if(children.length && children.length > 0) { //显示第一个子页面
				children[0].show();
				mui.fire(children[0],'show');
			}
		} else { //不存在则创建页面
			var options = _VIEW[id];
			options.show = {
				aniShow: animation,
				duration: time
			};
			options.waiting = {
				autoShow: false
			};
			options.extras = extras;
			mui.openWindow(options);
		}
	},

	//隐藏webview
	hide: function(id, callBack) {
		var view = plus.webview.getWebviewById(id);
		view && view.hide();
		callBack && callBack();
	},

	/*
	 * 创建webview
	 */
	create: function(views, parent) {
		parent = parent ? plus.webview.getWebviewById(parent) : undefined;
		if(!views.length) { //单个页面
			var view = plus.webview.create(views.url, views.id, views.styles ? views.styles : {});
			if(parent) parent.append(view);
		} else { //多个页面
			for(var i in views) {
				var view = plus.webview.create(views[i].url, views[i].id, views[i].styles ? views[i].styles : {});
				if(parent) parent.append(view);
				view.hide();
			}
		}
	}
}